package com.internetCafes.spms.web.customer.service.impl.customer;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.internetCafes.spms.common.utils.ShiroUtils;
import com.internetCafes.spms.web.customer.entity.customer.CustomerFlow;
import com.internetCafes.spms.web.customer.mapper.customer.CustomerFlowMapper;
import com.internetCafes.spms.web.customer.model.customer.flow.CustomerFlowDo;
import com.internetCafes.spms.web.customer.model.customer.flow.CustomerFlowPo;
import com.internetCafes.spms.web.customer.service.customer.ICustomerFlowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 客户流转表 服务实现类
 * </p>
 *
 * @author Zj
 * @since 2021-10-20
 */
@Service
public class CustomerFlowServiceImpl extends ServiceImpl<CustomerFlowMapper, CustomerFlow> implements ICustomerFlowService {

    @Override
    public List<CustomerFlowPo> listTransferPoRecent(List<Long> customerIdList) {
        return baseMapper.listTransferPoRecent(customerIdList);
    }

    @Override
    public List<CustomerFlowPo> poList(CustomerFlowDo customerFlowDo) {
        return baseMapper.poList(customerFlowDo);
    }

    @Override
    public Page<CustomerFlow> paging(IPage<CustomerFlow> page, Wrapper<CustomerFlow> queryWrapper) {
        return baseMapper.paging(page, queryWrapper);
    }

    @Override
    public boolean removeByCustomerIdList(List<Long> customerIdList) {
        return remove(new LambdaQueryWrapper<CustomerFlow>().in(CustomerFlow::getCustomerId, customerIdList));
    }

    @Override
    public boolean add(Long customerId, Integer actionTag, Long originalUserId, String originalUserName, Long targetUserId, String targetUserName) {
        CustomerFlow flowDo = new CustomerFlow()
                .setCustomerId(customerId)
                .setActionTag(actionTag)
                .setOriginalUserId(originalUserId)
                .setOriginalUserName(originalUserName)
                .setTargetUserId(targetUserId)
                .setTargetUserName(targetUserName)
                .setCreateByName(ShiroUtils.getUserEntity().getNickName());
        return save(flowDo);
    }

}
